//
//  UserGuideVC.m
//  HiZhua
//
//  Created by Jpwang on 2017/8/10.
//  Copyright © 2017年 Jpwang. All rights reserved.
//

#import "UserGuideVC.h"

@interface UserGuideVC () <UIScrollViewDelegate>

@property(weak, nonatomic) IBOutlet UIScrollView  *scrollview;
@property(weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation UserGuideVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initView];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initView {
    [self.scrollview setPagingEnabled:YES];
    [self.scrollview setDelegate:self];
    float width = [UIScreen mainScreen].bounds.size.width;
    float height = [UIScreen mainScreen].bounds.size.height;
    for (int i=0; i<3; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i*width, 0, width, height)];
        [imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d",i+1]]];
        [self.scrollview addSubview:imageView];
        if (i==4) {
            float scale = 1068/1280.0;
            float w = 121;
            float h = 80;
            UIButton *bt = [[UIButton alloc] initWithFrame:CGRectMake(width/2-w/2+i*width, scale*height-h/2, w, h)];
            [[bt rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
                [self.navigationController popViewControllerAnimated:YES];
            }];
            [self.scrollview addSubview:bt];
        }
    }
    self.scrollview.contentSize = CGSizeMake(3*width+1, 0);
    [self.scrollview setBounces:NO];
    [self.pageControl setHidden:YES];
//    [self.pageControl setNumberOfPages:5];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    int index = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    [self.pageControl setCurrentPage:index];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    NSLog(@"x=%f",scrollView.contentOffset.x);
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    float width = [UIScreen mainScreen].bounds.size.width;
    if (scrollView.contentOffset.x>width*2) {
        UIViewController *vc = [[UIStoryboard storyboardWithName:@"User" bundle:nil] instantiateViewControllerWithIdentifier:@"UserLoginVCID"];
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (BOOL)prefersStatusBarHidden {
    return YES;
}

@end































